#!/bin/sh

# Copyright(c) 2011 OpenDomo Services SL. Licensed under GPL v3 or later

echo -n "Loading local configuration "

if test -d /mnt/odconf/pkgcache 
then
	echo -n "..."
	# Preparing default configuration 
	if ! test -w /mnt/odconf/pdefault/ ; then
		/usr/bin/logger -p notice "Preparing default configuration dir"
		if mkdir -p /mnt/odconf/pdefault/; then
			cp /mnt/odconf/pkgcache/* /mnt/odconf/pdefault/ 2>/dev/null
			cp /mnt/odconf/sysconf/sysconf.tar.gz /mnt/odconf/pdefault/
		fi
	fi
else
	echo -n "[pkgcache not found!]"
	/usr/bin/logger -p error "Package cache directory not found"
	exit 1
fi
chown admin -R /var/pkg/installed 2> /dev/null

/usr/bin/logger -p notice "Loading configuration file"
mkdir -p /mnt/odconf/sysconf 2>/dev/null
chown 1000 /mnt/odconf/sysconf 2>/dev/null
/usr/local/opendomo/services/syscript/loadSystemConfiguration.sh >/dev/null

#/bin/logevent notice odpkg "Updating installed packages [start]"
#/usr/local/opendomo/updateInstalledPackages.sh  > /dev/null 
#/bin/logevent notice odpkg "Updating installed packages [end]"

# Loading language files from configuration, NOT from Internet
/usr/bin/logger -p notice "Updating language files"
#su -c /usr/local/opendomo/services/syscript/updateLanguageFiles.sh admin >/dev/null &
cp /etc/opendomo/langfiles/* /var/opendomo/i18n/

/usr/bin/logger -p notice "Triggering udev and ldconfig"
# Disparamos udev y ldconfig, por si hemos instalado controladores o librerias
/sbin/udevtrigger 2>/dev/null
/sbin/ldconfig 2>/dev/null
exit 0
